package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.commons.exception.LateException;
import com.woniuxy.controller.dto.ImgDto;
import com.woniuxy.dao.model.RepairAttachment;
import com.woniuxy.dao.RepairAttachmentDao;
import com.woniuxy.service.RepairAttachmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 附件表 服务实现类
 * </p>
 *
 * @author Keep it simple
 * @since 2022-06-28
 */
@Service
public class RepairAttachmentServiceImpl extends ServiceImpl<RepairAttachmentDao, RepairAttachment> implements RepairAttachmentService {

    @Resource
    private RepairAttachmentDao repairAttachmentDao;


    @Override
    public Integer addRepairArrachment(String repairNum, String oldfilename) {
        RepairAttachment repairAttachment = new RepairAttachment();
        repairAttachment.setOldfilename(oldfilename);
        repairAttachment.setRepairnum(repairNum);
        System.out.println(repairAttachment);
        System.out.println("+++++++++++++");
        int insert = repairAttachmentDao.insert(repairAttachment);
        if (insert==0){
            throw new LateException(1007,"新增附件失败");
        }
        return insert;
    }

    @Override
    public ImgDto getfilename(String repairNum) {
        QueryWrapper<RepairAttachment> repairAttachmentQueryWrapper = new QueryWrapper<>();
        repairAttachmentQueryWrapper.eq("repairNum",repairNum);
        RepairAttachment repairAttachment = repairAttachmentDao.selectOne(repairAttachmentQueryWrapper);
        ImgDto imgDto = new ImgDto();
        imgDto.setImg1(repairAttachment.getOldfilename());
        imgDto.setImg2(repairAttachment.getFilename());
        return imgDto;
    }
}
